import requests


# 获取音乐播放链接
def get_music_urls(song_ids):
    url = "http://127.0.0.1:3300/song/urls"
    params = {"id": song_ids}
    response = requests.get(url, params=params)
    if response.status_code == 200:
        data = response.json()
        if data["result"] == 100:
            return data["data"]
        else:
            print("Failed to get music URLs:", data)
    else:
        print("Failed to get music URLs. HTTP Status Code:", response.status_code)


# 获取音乐下载链接
def get_download_url(song_id):
    url = "http://127.0.0.1:3300/song/url"
    params = {"id": song_id}
    response = requests.get(url, params=params)
    if response.status_code == 200:
        data = response.json()
        print("Debug: Received data from server:", data)  # 继续保留调试信息
        if data["result"] == 100:
            return data["data"]  # 直接返回下载链接
        else:
            print("Failed to get download URL:", data)
    else:
        print("Failed to get download URL. HTTP Status Code:", response.status_code)

# 示例使用
if __name__ == "__main__":
    # 获取音乐播放链接
    song_ids = "000lD3pv0heA53"
    music_urls = get_music_urls(song_ids)
    if music_urls:
        print("Music URLs:", music_urls)

    # 获取音乐下载链接
    song_id = "000lD3pv0heA53"
    download_url = get_download_url(song_id)
    if download_url:
        print("Download URL:", download_url)
